home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac Mania 6
/
MacMania 6.toast
/
/
Tools&Utilities
/
RagTime External Functions Kit
/
FirstSample
/
FirstSample.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1997-04-24
|
3KB
|
106 lines
#include "FirstSample.h"
#include "RTXFunctsIntf.h"
#include "RTXBackCalls.h"
#include <Memory.h>
#include <OSUtils.h>
#include <Resources.h>
#include <ToolUtils.h>
//-------------------------------------------------------------------------------
// constant for string list defined in 'BXRl' resource, plus constants
// for the individual strings in the string list.
//-------------------------------------------------------------------------------
enum {
kValNilStr = 1,
kValNumStr,
kValBoolStr,
kValDateStr,
kValTextStr,
kValIntNumStr,
kUnknownValStr
};
//-------------------------------------------------------------------------------
// Prototypes
//-------------------------------------------------------------------------------
void FillInResultText (short theStrList, short theStrIndex,
RTValuePtr theValPtr);
//-------------------------------------------------------------------------------
// main
//-------------------------------------------------------------------------------
pascal short main (RTXPtr callBlock) {
short selector = callBlock->selector;
switch (selector) {
case kInitSelector:
case kQuitSelector: {
// nothing to do here
break;
}
case kOpenDocSelector:
case kCloseDocSelector:
case kActivateSelector:
case kDeactivateSelector: {
// these messages are only sent if 'kWantsMessagesFlag' is set
// in the 'BXDe' resource.
break;
}
case kTimeSelector: {
// this messages is only sent if 'needsTime' is set
// in the 'BXDe' resource.
break;
}
case kExampleAdd: {
// This function can accept either one or two parameters. If only one is
// received, then the result is 1 plus the parameter, otherwise the two
// parameters are added together.
callBlock->resultDest->valKind = valIntNum;
long firstLongInt = callBlock->parameter->eIntNum;
::GetNextParam (callBlock->backPtr);
if (callBlock->parameter == NULL) {
callBlock->resultDest->eIntNum = 1 + firstLongInt;
} else {
callBlock->resultDest->eIntNum = firstLongInt +
callBlock->parameter->eIntNum;
}
break;
}
case kIdentifyType: {
// This function returns text identifying the type of of the parameter.
callBlock->resultDest->valKind = valText;
short paramKind = callBlock->parameter->valKind;
short stringNo = kUnknownValStr; // in case of unknown value type
if (paramKind == valNil) stringNo = kValNilStr;
else if (paramKind == valNum) stringNo = kValNumStr;
else if (paramKind == valBool) stringNo = kValBoolStr;
else if (paramKind == valDate) stringNo = kValDateStr;
else if (paramKind == valText) stringNo = kValTextStr;
else if (paramKind == valIntNum) stringNo = kValIntNumStr;
FillInResultText (kResourceBase + 1, stringNo, callBlock->resultDest);
break;
}
}
return noErr;
};
//-------------------------------------------------------------------------------
// Fill in the RTValueRec pointed to by theValPtr with the text
// specified by the string list and index.
//-------------------------------------------------------------------------------
void FillInResultText (short theStrList, short theStrIndex,
RTValuePtr theValPtr) {
Str255 theString;
::GetIndString (theString, theStrList, theStrIndex);
short length = (short) theString[0];
theValPtr->t.eTextLen = length;
theValPtr->t.eTextHdl = ::NewHandle (length);
::BlockMove (&(theString[1]), *(theValPtr->t.eTextHdl), length);
};